<?php 
	ob_start(); session_start(); 
	require_once('adminpanel/config/setting.php');
	if(!($_SESSION['memberid'])){
		header('Location: login-warning.php');		
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Reservation</title>
</head>
<style>
	.topmenu{
		font-family:arial;
		font-size:14px;
		color:#FFFFFF;
		text-decoration:none;
	}
	.topmenu:hover{
		font-family:arial;
		font-size:14px;
		color:#FFFFFF;
		text-decoration:underline;
	}
</style>
<style>
.dayselect{
	font-family:verdana;
	font-size:12px;
	color:#003399;
	font-weight:bold;
	text-decoration:none;
}	

.dayselect:hover{
	font-family:verdana;
	font-size:12px;
	color:#0099FF;
	font-weight:bold;
	text-decoration:none;
}	

.stepfont{
	font-family:verdana; 
	font-size:12px; 
	color:#0066CC;
	text-decoration:none;
}

.stepfont:hover{
	font-family:verdana; 
	font-size:12px; 
	color:#E566BD;
	text-decoration:underline;
}

</style>

<script language="JavaScript">

var ns6=document.getElementById&&!document.all
var ie4=document.all

var Selected_Month;
var Selected_Year;
var Current_Date = new Date();
var Current_Month = Current_Date.getMonth();

var Days_in_Month = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var Month_Label = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

var Current_Year = Current_Date.getYear();
if (Current_Year < 1000)
Current_Year+=1900


var Today = Current_Date.getDate();

function Header(Year, Month) {

   if (Month == 1) {
   Days_in_Month[1] = ((Year % 400 == 0) || ((Year % 4 == 0) && (Year % 100 !=0))) ? 29 : 28;
   }
   var Header_String = Month_Label[Month] + ' ' + Year;
   return Header_String;
}



function Make_Calendar(Year, Month) {
   var First_Date = new Date(Year, Month, 1);
   var Heading = Header(Year, Month);
   var First_Day = First_Date.getDay() + 1;
   if (((Days_in_Month[Month] == 31) && (First_Day >= 6)) ||
       ((Days_in_Month[Month] == 30) && (First_Day == 7))) {
      var Rows = 6;
   }
   else if ((Days_in_Month[Month] == 28) && (First_Day == 1)) {
      var Rows = 4;
   }
   else {
      var Rows = 5;
   }

   var HTML_String = '<table style="font-family:verdana;font-size:12px;color:#333333;"><tr><td valign="top"><table BORDER=0 CELLSPACING=1 cellpadding=4 FRAME="box" BGCOLOR="#76AFEF" BORDERCOLORLIGHT="#808080">';
   HTML_String += '<tr><th colspan=7 BGCOLOR="#FFFFFF" BORDERCOLOR="#000000" >' + Heading + '</font></th></tr>';
   HTML_String += '<tr><th ALIGN="CENTER" BGCOLOR="#FFFFFF" BORDERCOLOR="#000000">Sun</th><th ALIGN="CENTER" BGCOLOR="#FFFFFF" BORDERCOLOR="#000000">Mon</th><th ALIGN="CENTER" BGCOLOR="#FFFFFF" BORDERCOLOR="#000000">Tue</th><th ALIGN="CENTER" BGCOLOR="#FFFFFF" BORDERCOLOR="#000000">Wed</th>';
   HTML_String += '<th ALIGN="CENTER" BGCOLOR="#FFFFFF" BORDERCOLOR="#000000">Thu</th><th ALIGN="CENTER" BGCOLOR="#FFFFFF" BORDERCOLOR="#000000">Fri</th><th ALIGN="CENTER" BGCOLOR="#FFFFFF" BORDERCOLOR="#000000">Sat</th></tr>';

   var Day_Counter = 1;
   var Loop_Counter = 1;
   for (var j = 1; j <= Rows; j++) {
      HTML_String += '<tr ALIGN="left" VALIGN="top">';
      for (var i = 1; i < 8; i++) {
         if ((Loop_Counter >= First_Day) && (Day_Counter <= Days_in_Month[Month])) {
            if ((Day_Counter == Today) && (Year == Current_Year) && (Month == Current_Month)) {
               HTML_String += '<td BGCOLOR="#FFFFFF" BORDERCOLOR="#000000"><strong><font color="red">' + Day_Counter + '</font></strong></td>';
            }
            else {
				if(Year > Current_Year){
					HTML_String += '<td BGCOLOR="#FFFFFF" BORDERCOLOR="#000000"><a href="reservation.php?step=2&nday='+Day_Counter+'&nmonth='+(Number(Month)+1)+'&nyear='+Year+'" class="dayselect">' + Day_Counter + '</a></td>';
				}else if(Month > Current_Month){
					HTML_String += '<td BGCOLOR="#FFFFFF" BORDERCOLOR="#000000"><a href="reservation.php?step=2&nday='+Day_Counter+'&nmonth='+(Number(Month)+1)+'&nyear='+Year+'" class="dayselect">' + Day_Counter + '</a></td>';
				}else if(Month == Current_Month){
					if(Day_Counter > Today){
            		   HTML_String += '<td BGCOLOR="#FFFFFF" BORDERCOLOR="#000000"><a href="reservation.php?step=2&nday='+Day_Counter+'&nmonth='+(Number(Month)+1)+'&nyear='+Year+'" class="dayselect">' + Day_Counter + '</a></td>';
					}else{
					   HTML_String += '<td BGCOLOR="#FFFFFF" BORDERCOLOR="#000000">' + Day_Counter + '</td>';
					}   
				}else{	
				   HTML_String += '<td BGCOLOR="#FFFFFF" BORDERCOLOR="#000000">' + Day_Counter + '</td>';
				}   
            }
            Day_Counter++;    
         }
         else {
            HTML_String += '<td BORDERCOLOR="#C0C0C0"> </td>';
         }
         Loop_Counter++;
      }
      HTML_String += '</tr>';
   }
   HTML_String += '</table></td></tr></table>';
   cross_el=ns6? document.getElementById("Calendar") : document.all.Calendar
   cross_el.innerHTML = HTML_String;
}


function Check_Nums() {
	var xtmpCurrent_Date = new Date();	
	var xtmpCurrent_Year = xtmpCurrent_Date.getYear();
	var xtmpyear = document.when.year.value;
	if (xtmpCurrent_Year < 1000) xtmpCurrent_Year+=1900

    if ((event.keyCode < 48) || (event.keyCode > 57)) {
	  return false;
    }else if(xtmpyear > (xtmpCurrent_Year+1)){
	  alert('Warning! Invalid Year Please Check.');	
	  return false;
	}else if(xtmpyear < xtmpCurrent_Year){	  	
	  alert('Warning! Invalid Year Please Check.');	
	  return false;
	}
}


function checkYear(){
	Skip('+');
	var xtmpCurrent_Date = new Date();	
	var xtmpCurrent_Year = xtmpCurrent_Date.getYear();
	var xtmpyear = document.when.year.value;
	if (xtmpCurrent_Year < 1000) xtmpCurrent_Year+=1900
	if(xtmpyear > (xtmpCurrent_Year+1)){
	  alert('Warning! Invalid Year Exceeds Limit.');	
	  Skip('-');
	  return false;
	}else if(xtmpyear < xtmpCurrent_Year){	  	
	  alert('Warning! Invalid Year Exceeds Limit.');	
	  Skip('-');
	  return false;
	}
}

function On_Year() {
   var Year = document.when.year.value;
   if (Year.length == 4) {
      Selected_Month = document.when.month.selectedIndex;
      Selected_Year = Year;
      Make_Calendar(Selected_Year, Selected_Month);
   }
}

function On_Month() {
   var Year = document.when.year.value;
   if (Year.length == 4) {
      Selected_Month = document.when.month.selectedIndex;
      Selected_Year = Year;
      Make_Calendar(Selected_Year, Selected_Month);
   }
   else {
      alert('Please enter a valid year.');
      document.when.year.focus();
   }
}


function Defaults() {
   if (!ie4&&!ns6)
   return
   var Mid_Screen = Math.round(document.body.clientWidth / 2);
   document.when.month.selectedIndex = Current_Month;
   document.when.year.value = Current_Year;
   Selected_Month = Current_Month;
   Selected_Year = Current_Year;
   Make_Calendar(Current_Year, Current_Month);
}


function Skip(Direction) {
   if (Direction == '+') {
      if (Selected_Month == 11) {
         Selected_Month = 0;
         Selected_Year++;
      }
      else {
         Selected_Month++;
      }
   }
   else {
      if (Selected_Month == 0) {
         Selected_Month = 11;
         Selected_Year--;
      }
      else {
         Selected_Month--;
      }
   }
   Make_Calendar(Selected_Year, Selected_Month);
   document.when.month.selectedIndex = Selected_Month;
   document.when.year.value = Selected_Year;
}

function CheckMonth()
{
	var tmpCurrent_Date = new Date();	
	var tmpCurrent_Month = tmpCurrent_Date.getMonth();
	var tmpCurrent_Year = tmpCurrent_Date.getYear();
	if (tmpCurrent_Year < 1000) tmpCurrent_Year+=1900
  	var tmpyear = document.when.year.value;
  	var tmpmonth = document.when.month.value;
	if(tmpCurrent_Year == tmpyear){
		if(tmpmonth <= tmpCurrent_Month){
		   alert('Warning! Invalid Reservation Date, Past Date Is Not Accepted');	
		   return false;
		}else{
		   Skip('-');		   	
		   return true;
		}
	}else if(tmpyear < tmpCurrent_Year){
	   alert('Warning! Invalid Reservation Date, Past Date Is Not Accepted');	
	   return false;
	}else{
		   Skip('-');		   	
		   return true;
	}
  
}

</script>

<?php 
	if($_GET['step']=='4' && !empty($_GET['table']) && !empty($_GET['time']) && !empty($_GET['nday']) && !empty($_GET['nmonth']) && !empty($_GET['nyear'])) {
		$selected_table = $_GET['table'];
		$selected_time = $_GET['time'];
		$selected_date = $_GET['nmonth'].'/'.$_GET['nday'].'/'.$_GET['nyear'];
		$datein = time();
		$mid = $_SESSION['memberid'];
		mysql_query("insert into tbl_reservation (id,mid,selected_date,selected_table,selected_time,status,dateposted) values ('','$mid','$selected_date','$selected_table','$selected_time','1','$datein')") or die (mysql_error());
		header('Location: reservation.php?step=4');		
	}
?>

<body style="margin:0px; background-color:#f1f1f1" onload="Defaults();">
	<div id="header" style="background:url(images/top-bg.png) repeat-x; " align="center">
    	<div style="width:982px;" >
        	<div style="padding-top:30px; padding-right:20px; color:#FFFFFF" align="right">
            	<img src="images/the-century-logo.png" style="top:20px; margin-left:50px;" align="left" />
            	<a href="index.php" class="topmenu">Home</a> &nbsp; | &nbsp; 
                <a href="about-us.php" class="topmenu">About Us</a> &nbsp; | &nbsp; 
                <a href="questions.php" class="topmenu">Questions</a> &nbsp; | &nbsp; 
                <a href="reservation.php" class="topmenu"><font size="5px">Reservation</font></a> &nbsp; | &nbsp; 
				<a href="menu.php" class="topmenu">Menu</a> &nbsp; | &nbsp; <?php if(!($_SESSION['username'])){?>
                <a href="signup.php" class="topmenu">Signup</a><?php } else {?>
                <a href="logout.php" class="topmenu">Logout</a><?php }?>
                <br /><br/>
                <?php 
                include('login.php');
				?>            
            </div>
        	<img src="images/top-gradient.png" />
            <div style="position:absolute; top:200px; margin-left:50px; font-size:24px; color:#F00 ">Reservation</div>
        </div>
    </div>
	<div id="body" style="height:500px" align="center">
    	<div style="width:982px; height:auto; background-color:#f1f1f1"  align="center">
            <div style="width:900px;margin-left:0px; line-height:18px; font-family:verdana; font-size:12px; color:#666" align="left" >
            	<div style="width:200px;  height:auto; float:left" align="right">
                	<table width="180px" bgcolor="#f1f1f1" cellpadding="0" cellspacing="0" border="0">
                    	<?php if($_GET['step']==''){$_GET['step']=1;}?>
                    	<tr><td height="100px"><img <?=(($_GET['step']==1)?'src="images/step1-on.png"': 'src="images/step1-off.png"');?> align="left" /> <b style="color:<?=(($_GET['step']==1)? '#c1263d':'#0066cc')?>">Select Date</b> <div style="width:105px; height:10px; float:right; background-color:<?=(($_GET['step']==1)?'#c1263d':'#f1f1f1');?>" ></div></td></tr>
						<tr><td height="100px"><img <?=(($_GET['step']==2)?'src="images/step2-on.png"': 'src="images/step2-off.png"');?> align="left" /> <b style="color:<?=(($_GET['step']==2)? '#c1263d':'#0066cc')?>">Select Slot</b> <div style="width:105px; height:10px; float:right; background-color:<?=(($_GET['step']==2)?'#c1263d':'#f1f1f1');?>" ></div></td></tr>
						<tr><td height="100px"><img <?=(($_GET['step']==3)?'src="images/step3-on.png"': 'src="images/step3-off.png"');?> align="left" /> <b style="color:<?=(($_GET['step']==3)? '#c1263d':'#0066cc')?>">Confirmation</b> <div style="width:105px; height:10px; float:right; background-color:<?=(($_GET['step']==3)?'#c1263d':'#f1f1f1');?>" ></div></td></tr>
                    </table>
                </div>
                <div style="width:700px; float:left">
                	<table width="600px">
                    	<tr>
                        	<td>
                            <?php 
								if($_GET['step']=='1'){
									include('step1.php');
								}
								
								if($_GET['step']=='2'){
									include('step2.php');
								}	
								
								if($_GET['step']=='3'){
									include('step3.php');
								}	
								
								if($_GET['step']=='4'){
									echo '<span style="font-size:18px; color:red">Reservation Successfully Submitted.</span>';
								}	
								
s							?>	
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div id="footer" style="background:url(images/btm-bg.png) repeat-x; height:166px" align="center">
    	<div style="width:982px">
        	<div style="height:40px"></div>
        	<img src="images/btm-gradient.png" />
        </div>
    		
    </div>
</body>
</html>